package cn.humaohua.study.yanmo_design_pattern.ch13.v2;

public class Main {
    public static void main(String[] args) {
        // 命令接收者（真正执行命令的对象）
        OperationApi operation = new Operation();
        // 加命令
        Command addCommand = new AddCommand(operation, 5);
        // 计算器
        Calculator calculator = new Calculator();
        // 为计算器设置加命令
        calculator.setAddCommand(addCommand);
        // 加操作之前，结果
        System.out.println("加之前：" + operation.getResult());
        calculator.addPressed();
        // 加之后，结果
        System.out.println("加之后：" + operation.getResult());

        Command substractCommand = new SubstractCommand(operation, 2);
        calculator.setSubstractCommand(substractCommand);
        calculator.substractPressed();
        System.out.println("减之后：" + operation.getResult());

        calculator.undoPressed();
        System.out.println("after undo:" + operation.getResult());

        calculator.redoPressed();
        System.out.println("after redo:" + operation.getResult());
        calculator.redoPressed();

        calculator.undoPressed();
        System.out.println("after undo:" + operation.getResult());
        calculator.undoPressed();
        System.out.println("after undo:" + operation.getResult());
    }
}
